import React from 'react';
import NavTitle from '../../workzone/basedata/navleft/NavTitle.jsx';
import ModuleItem from './ModuleItem.jsx';
import {Radio } from 'antd';

class ModulesSelect extends React.Component{
  static Prototypes: {
    visible: PropTypes.bool.isRequired,
    options: PropTypes.array.isRequired,
    setMenus: PropTypes.func.isRequired,
    hide: PropTypes.func.isRequired

  }

  constructor(props) {
    super(props);

    this.state = {
      menu: {

      }
    }
  }

  mergeMenus(obj) {
    let {key, data, add, force} = obj;
    
    var that = this;
    this.props.options.map(function(opt){
      if(opt.value !== key) {
        that.refs[opt.value].forceUnselectAll();
      }
      else {
        let menus = [];
        if(data.length !== 0) {
          opt.kids.map(function(item){
            data.map(function(d){
              if(item.value === d) {
                menus.push(item);
              }
            })  
          })
        }
        that.props.setMenus(menus);
      }
    });

    this.props.hide();
  }

  render() {
    let styleName = "nav-vertical modules-select " + (this.props.visible ? "" : "hide" );
    let lists = [];
    var that = this;
    if(this.props.options.length>0) {
      this.props.options.map(function(opt){
        lists.push(<ModuleItem ref={opt.value} key={opt.value} 
          itemId={opt.value} plainOptions={opt} changeMenus={that.mergeMenus.bind(that)} />);
      });
    }
    
    return (
      <div className={styleName}>
        <div className="title">
          <span className="main">功能模块</span>
        </div>       
        {lists}    
      </div>
    );
  }
}; 

export default ModulesSelect;


